/*
 * Copyright (c) 2013 Johann Hanne
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

#ifndef _I2C_H
#define _I2C_H

#include <stdlib.h>
#include <stdint.h>

typedef int i2c_status_t;

#define I2C_OK              ((i2c_status_t)0)
#define I2C_SCL_STUCK_LOW   ((i2c_status_t)1)
#define I2C_SDA_STUCK_LOW   ((i2c_status_t)2)
#define I2C_NACK_ON_ADDRESS ((i2c_status_t)3)
#define I2C_NACK_ON_DATA    ((i2c_status_t)4)

void i2c_init(void);
i2c_status_t i2c_write_restart_read(uint8_t addr_w, uint8_t *data_w, size_t len_w,
        uint8_t addr_r, uint8_t *data_r, size_t len_r);

#define i2c_write(addr_w, data_w, len_w) \
    i2c_write_restart_read(addr_w, data_w, len_w, 0, NULL, 0)

#define i2c_read(addr_r, data_r, len_r) \
    i2c_write_restart_read(0, NULL, 0, addr_r, data_r, len_r)

#endif /* _I2C_H */
